longest common prefix using trie